<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>房间合并</title>

<link rel="stylesheet" href="js/bootstrap2/css/bootstrap.min.css">
<link rel="stylesheet" href="css/common.css">
<style type="text/css">
	#roomNum th {
		background: #d70b16;
		color: #fff;
	}
	.check{
		width: 35px;
	}
	.foot{
		text-align: left !important;
		/* padding-right: 50px !important; */
	}
</style>
</head>
<body>
	<div>
		<table id="roomNum" class="table table-bordered">
			<thead>
				<tr>
					<th class="check"><input id="checkAll" type="checkbox"></th>
					<c:if test="${not empty pid}">
						<th>楼号</th>
						<th>单元</th>
						<th>楼层</th>
					</c:if>
					<th>房间号</th>
					<th>建筑面积</th>
					<th>套内建面</th>
					<th>户型</th>
					<th>朝向</th>
					<th>用途</th>
					<th>状态</th>
				</tr>
			</thead>
			<tbody class="content" style="background:#eee">
				<c:if test="${empty requestScope.canMergeRoom }">
					<tr>
						<c:if test="${not empty pid}">
							<td colspan="11" >没有可合并的房间...</td>
						</c:if>
						<c:if test="${empty pid}">
							<td colspan="8" >没有可合并的房间...</td>
						</c:if>
					</tr>
				</c:if>
				<c:forEach items="${requestScope.canMergeRoom }" var="t" >
					<tr>
						<td><input type="checkbox" value="${pageScope.t.id }" ></td>
						<c:if test="${not empty pid}">
							<td>${pageScope.t.noName }</td>
							<td>${pageScope.t.unitName }</td>
							<td>${pageScope.t.floorName }</td>
						</c:if>
						<td>${pageScope.t.roomNum }</td>
						<td>${pageScope.t.buildingArea } ㎡</td>
						<td>${pageScope.t.setInArea } ㎡</td>
						<td>${pageScope.t.houseType }</td>
						<td>${pageScope.t.direction }</td>
						<td>${pageScope.t.roomUse }</td>
						<td>${pageScope.t.roomStatus }</td>
					</tr>
				</c:forEach>
			</tbody>
			<tfoot>
				<tr>
					<td class="foot" colspan="9">
						<c:if test="${cusIndentity=='1'}">
							<span>合并时间:</span>
							<input id="extDate" class="Wdate" onClick="WdatePicker({ dateFmt: 'yyyy-MM-dd'})" />
							&nbsp;&nbsp;
							<span>复制装饰信息:</span>
							<input type="radio"value="0" name="isCopy" >是
							<input type="radio" value="1" name="isCopy" checked="checked">否
							<span style="color:red;font-size:11px;">*是否复制装饰信息到扩租的房间下面</span>
							&nbsp;
							<button id="runExtRoom" class="btn btn-danger radius">确认合并</button>
						</c:if>
						<c:if test="${cusIndentity=='0'}">
							<button id="runExtRoom" class="btn btn-danger radius">确认复制</button>
						</c:if>
					</td>
				</tr>
			</tfoot>
		</table>
	</div>
</body>
<script type="text/javascript" src="js/jquery-1.11.1.js"></script>
<script type="text/javascript" src="js/layui-v2.1.5/layui/layui.all.js"></script>
<script type="text/javascript" src="<%=basePath%>js/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	$(function(){
		//全选、全不选
		$("#checkAll").click(checkAll);
		$("tbody.content input[type='checkbox']").click(checkEvery);
		
		//合并事件
		$("#runExtRoom").click(runExtRoom);
	});
	//点击全选按钮 选中、不选中所有
	function checkAll(){
		$("tbody.content input[type='checkbox']").prop("checked",$(this).prop("checked"));
	}
	//点击某一个复选都进行判断，反向控制全选按钮
	function checkEvery(){
		var len=<c:out value="${fn:length(requestScope.canMergeRoom)}" default="0"></c:out>;
		var checkLen = $("tbody.content input[type='checkbox']:checked").length;
		if(len==checkLen){
			$("#checkAll").prop("checked",true);
		}else{
			$("#checkAll").prop("checked",false);
		}
	}
	
	//开始合并
	function runExtRoom(){
		var cusIndentity = '${cusIndentity}';
		var extDate=$("#extDate").val();
		var isCopy = $("input[name='isCopy']:checked").val();//是否要复制装饰信息
		if(cusIndentity == '1'){//租赁人
			if(extDate){
				//输入备注信息
				layer.prompt({title: '输入备注信息，并确认', formType: 2,shade: [0.1, '#fff'],offset: '10%'}, function(remark, index){
					layer.close(index);
					submitExt(remark,extDate,isCopy);
				});
			}else{
				$("#extDate").focus();
				layer.msg("请输入扩租时间");
			}
		}else{//产权人
			isCopy = '1';
			//输入备注信息
			layer.prompt({title: '输入备注信息，并确认', formType: 2,shade: [0.1, '#fff'],offset: '10%'}, function(remark, index){
				layer.close(index);
				submitExt(remark,extDate,isCopy);
			});
		}
	}
	//向服务器提交信息
	function submitExt(remark,extDate,isCopy){
		var index = layer.load(2);
		var customerId='${requestScope.customerId}';
		var roomId='${requestScope.roomId}';
		//获取所有被选中的复选框
		var $checkbox=$("tbody.content input[type='checkbox']:checked");
		//var roomId='${requestScope.roomId}';//发起合并功能的房间id
		var checkRoom=new Array();//记录被合并的房间id
		$.each($checkbox,function(i,v){
			checkRoom.push($(v).val());
		});
		$.post("customerInfo/runExtRoom",{
				extRoomId:checkRoom.toString(),
				customerId:customerId,
				remark:remark,
				extDate:extDate,
				isCopy:isCopy,
				roomId:roomId
			},function(data){
				layer.close(index);
				index=layer.alert("操作成功",{
					shade: [0.1, '#eee']
				},function(){
					layer.close(index);
					location.reload(true);
				});
		});
	}
	
</script>
</html>